package jjn.round2;

import commons.ListNode;

/**
 * @author Jiang Jining
 * @since 2023-05-07 23:17
 */
public class Offer52_GetIntersectionNode {
    ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) {
            return null;
        }
        ListNode first = headA, second = headB;
        while (first != second) {
            first = first == null ? headB : first.next;
            second = second == null ? headA : second.next;
        }
        return first;
    }
}
